import { createRouter, createWebHistory } from 'vue-router'

import Layout from '@/components/Layout.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "layout",
      component: Layout,
      redirect: "/dashboard",
      children: [
        {
          path: "/dashboard",
          name: "Dashboard",
          component: () => import("@/views/Dashboard.vue"),
          meta: { title: '仪表盘' }
        },
        {
          path: "/statistics",
          name: "Statistics",
          redirect: "/statistics/asset-overview",
          meta: { title: '统计分析' },
          children: [
            {
              path: "asset-overview",
              name: "AssetOverview",
              component: () => import("@/views/statistics/AssetOverview.vue"),
              meta: { title: '资产概览' }
            },
            {
              path: "status-distribution",
              name: "StatusDistribution",
              component: () => import("@/views/statistics/StatusDistribution.vue"),
              meta: { title: '状态分布' }
            },
            {
              path: "dept-distribution",
              name: "DeptDistribution",
              component: () => import("@/views/statistics/DeptDistribution.vue"),
              meta: { title: '部门分布' }
            },
            {
              path: "asset-ledger",
              name: "AssetLedger",
              component: () => import("@/views/statistics/AssetLedger.vue"),
              meta: { title: '资产台账' }
            },
            {
              path: "asset-transfer",
              name: "AssetTransfer",
              component: () => import("@/views/statistics/AssetTransfer.vue"),
              meta: { title: '资产流转报表' }
            },
            {
              path: "dept-heat",
              name: "DeptHeat",
              component: () => import("@/views/statistics/DeptHeat.vue"),
              meta: { title: '部门领用热度' }
            }
          ]
        },
        {
          path: "/check",
          name: "Check",
          redirect: "/check/plan",
          meta: { title: '资产盘点' },
          children: [
            {
              path: "check-plan",
              name: "CheckPlan",
              component: () => import("@/views/check/CheckPlan.vue"),
              meta: { title: '盘点计划' }
            },
            {
              path: "check-plan-settings",
              name: "CheckPlanSettings",
              component: () => import("@/views/check/CheckPlanSettings.vue"),
              meta: { title: '盘点计划设置' }
            },
            {
              path: "check-progress",
              name: "CheckProgress",
              component: () => import("@/views/check/CheckProgress.vue"),
              meta: { title: '盘点进度' }
            },
            {
              path: "check-record",
              name: "CheckRecord",
              component: () => import("@/views/check/CheckRecord.vue"),
              meta: { title: '盘点记录' }
            },


          ]
        },
        {
          path: "/asset",
          name: "Asset",
          redirect: "/asset/others",
          meta: { title: '资产管理' },
          children: [   
           {
              path: "stovkIn",
              name: "AssetStockIn",
              component: () => import("@/views/asset/AssetStockIn.vue"),
              meta: { title: '入库申请' }
            },
            {
              path: "others",
              name: "Others",
              component: () => import("@/views/asset/Others.vue"),
              meta: { title: '其他操作' }
            },
            {
              path: "apply",
              name: "AssetApply",
              component: () => import("@/views/asset/AssetApply.vue"),
              meta: { title: '' }
            },
            {
              path: "check-record",
              name: "CheckRecord",
              component: () => import("@/views/check/CheckRecord.vue"),
              meta: { title: '领用申请' }
            }
          ]
        },
        {
          path: "/home",
          name: "home",
          component: () => import("@/views/layout/Home.vue"),
        }
      ],
    },
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/Login.vue"),
      meta: { title: '登录' }
    }
  ],
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? `${to.meta.title} - 小微资产管理系统` : '小微资产管理系统'
  next()
})

export default router
